﻿<%@ Page Language="C#" %>
<%@ Register TagPrefix="IRL" TagName="SideBar" Src="SideBar.ascx" %>
<%@ Import Namespace="IRL.Utilities" %>
<%@ Import Namespace="System.Drawing" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>

<script runat="server">
    public const int CURRENT_MODULE = 51;
    
    //Hashtable ptype_lookup, rcat_lookup;
    int pageSize = 20;

    protected void Page_Load(object src, EventArgs e)
    {
        Security SysAcc = new Security(CURRENT_MODULE);
        // check is authenticate
        SysAcc.Authenticate();
        // load reminder count        
        //Mics.loadReminderCount(lblReminderCount);
        
        //ptype_lookup = Lookup.Fill("sp_Select_cms_Lookup 'project_type'", conn);
        //rcat_lookup = Lookup.Fill("sp_Select_cms_Lookup 'research_category_s'", conn);

        //pageSize = 1;
        SideBar1.loadData();
        if (!Page.IsPostBack)
        {
            grid1.Attributes.Add("sortFld", "ProjectName");
            grid1.Attributes.Add("sortDir", "ASC");
            rebind();
        }        
    }

    // bind to datagrid
    void rebind()
    {
        string market = "";
        if (Request.Cookies["office"] != null)
            market = Request.Cookies["office"].Value;
        object connStr = ConfigurationSettings.AppSettings["sqlConn"];
        using (SqlConnection conn = new SqlConnection(connStr.ToString()))
        {
            SqlDataAdapter adapter = new SqlDataAdapter("sp_ListProposals", conn);
            adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
            adapter.SelectCommand.Parameters.Add("@userid", SqlDbType.Int).Value = Request.Cookies["irl_id"].Value;
            adapter.SelectCommand.Parameters.Add("@IsArchived", SqlDbType.Bit).Value = 1;
            if (market != "")
                adapter.SelectCommand.Parameters.Add("@market", SqlDbType.Int).Value = market;
            DataTable dt = new DataTable();
            DataView dv;
            adapter.Fill(dt);
            dv = dt.DefaultView;
            dv.Sort = grid1.Attributes["sortFld"] + " " + grid1.Attributes["sortDir"];
            // Bind to Grid                
            grid1.DataSource = dv;
            grid1.DataBind();
            if (grid1.PageCount == 1)
                grid1.PagerStyle.Visible = false;
            // save to sort expr to viewState
            //Session.Add("sortExpr", dv.Sort);                
            Session["sortExpr"] = dv.Sort;
        }
    }        

    protected void grid1_SortCommand(object source, DataGridSortCommandEventArgs e)
    {
        string strSort = grid1.Attributes["sortFld"];
        string strOrder = grid1.Attributes["sortDir"];
        string strSortExpr = e.SortExpression;
        
        if (strSort == strSortExpr && strOrder == "ASC")
        {
            strOrder = "DESC";
        }
        else
        {
            strOrder = "ASC";
        }
        if (strSortExpr!=strSort && strSortExpr == "ForYear")
        {
            strOrder = "DESC";
        }
        
        grid1.Attributes["sortFld"] = strSortExpr;
        grid1.Attributes["sortDir"] = strOrder;        
        rebind();
        
    }

    protected void grid1_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
    {
        if (e.NewPageIndex > -1)
        {
            grid1.CurrentPageIndex = e.NewPageIndex;
            rebind();
        }
    }

    string showStatus(string stat, string pid)
    {
        string strHtml = "";
        switch (stat)
        {
            case "Need Cost Confirmation":
                strHtml = "<a href=\"saveProject.aspx?pid=" + pid + "&confirm=1\" title=\"Confirm Now\">Need Confirm</a>";
                break;
            case "Not Commissioned":
                strHtml = "Not Commissioned";
                //strHtml = "<img src=\"images/banicon.gif\" title=\"Not Commissioned\" />";
                break;
            case "Commissioned Already":
                strHtml = "<img src=\"images/tickicon.gif\" title=\"Commissioned Already\" />";
                break;
        }

        return strHtml;
    }
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="Description" content="Providing the tools and expertise needed to navigate in the emerging consumer markets of Indochina.">
    <meta name="keywords" content="Research in Indochina, Research Consultants in Indochina, Marketing Research in Indochina, Marketing Research Companies in Indochina, Marketing Consultants in Indochina Research in Vietnam, Research Consultants in Vietnam, Marketing Research in Vietnam, Marketing Research Companies in Vietnam, Marketing Consultants in Vietnam Research in Cambodia, Research Consultants in Cambodia, Marketing Research in Cambodia, Marketing Research Companies in Cambodia, Marketing Consultants in Cambodia Research in Laos, Research Consultants in Laos, Marketing Research in Laos, Marketing Research Companies in Laos, Marketing Consultants in Laos">
    <meta name="robots" content="all">

    <title>Indochina Research</title>
    <link href="../css/global.css" rel="stylesheet" type="text/css" />
    <link href="css/cms.css" rel="stylesheet" type="text/css" />
    
    
</head>
<body>
<table width="773" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<td width="765" height="540" align="center" valign="top" style="border:solid 1px #10147e;" >
			<!-- header -->
			<table border="0" cellpadding="0" cellspacing="0" width="100%">
				<tr bgcolor="#F4F4F9">
					<td colspan="3" align="right" style="padding:10px;">
						<b class="blueL">Client Management System</b>
					</td>
				</tr>
				<tr>
					<td class="wave_l">&nbsp;</td>
					<td><img src="images/wave_logo.jpg" width="107" height="83"></td>
					<td class="wave_r">&nbsp;</td>
				</tr>
				<tr>
					<td colspan="3" style="padding:0 20px;">
						<div style="background-color:#bcb3d5; padding:5px 10px;">
							<span style="float:right">

								&nbsp;</span>
							<span class="pathmap">
								<a href="default.aspx" >CPanel</a> :: 
								<a href="default2.aspx" >Ops Files</a> :: 
								Archived Proposals
						  </span>
						</div>
						<br />
						
						
					</td>
				</tr>
				
			</table>
			
			<!-- body -->
			<form id="DataForm" method="post" runat="server">
			<table border="0" width="100%" cellspacing="0" cellpadding="0">
				<tr>
					<td align="center" valign="top" style="padding-left:20px;">
						<table align="left" border="0" cellspacing="0" cellpadding="0">
							<tr>
								<td valign="top">
								
									<IRL:SideBar ID="SideBar1" runat="server" />
								
								</td>
								<td width="10"><img src="images/spacer.gif" width="10" height="1" /></td>
								<td valign="top">
								    <div style="width:480px; overflow:auto; overflow-y:visible">
									<asp:DataGrid ID="grid1" CssClass="data" Width="100%" AutoGenerateColumns="false" runat="server"
                                        CellSpacing="1" CellPadding="4" BorderWidth="0" GridLines="none" 
                                        AllowSorting="true" AllowPaging="true" PageSize="<%# pageSize %>" 
                                        OnSortCommand="grid1_SortCommand"
                                        OnPageIndexChanged="grid1_PageIndexChanged">
                                        <HeaderStyle CssClass="header" />
                                        <ItemStyle BackColor="#efefef" />
                                        <AlternatingItemStyle BackColor="white" />
                                        <PagerStyle Mode="numericpages" HorizontalAlign="center" />
                                        <Columns>
                                            <asp:TemplateColumn HeaderText="No">
                                                <HeaderStyle Width="20" />
                                                <ItemTemplate>
                                                    <%# (grid1.CurrentPageIndex*pageSize)+Container.ItemIndex+1%>
                                                </ItemTemplate>
                                            </asp:TemplateColumn>
                                            
                                            <asp:BoundColumn HeaderText="Year" DataField="ForYear" SortExpression="ForYear">
                                                <HeaderStyle Width="30" />
                                            </asp:BoundColumn>
                                            <asp:BoundColumn HeaderText="Client Name" DataField="ClientName" SortExpression="ClientName">
                                                <HeaderStyle Width="280" />
                                            </asp:BoundColumn>
                                            <asp:HyperLinkColumn HeaderText="Project Name" DataTextField="ProjectName" SortExpression="ProjectName"
                                                DataNavigateUrlField="ProposalID" DataNavigateUrlFormatString="saveProposal.aspx?pid={0}">
                                                <HeaderStyle Width="160" />
                                            </asp:HyperLinkColumn>
                                            <asp:BoundColumn HeaderText="Value" DataField="Costs" SortExpression="Costs" DataFormatString="{0:$#,##0}">
                                                <HeaderStyle Width="60" />
                                            </asp:BoundColumn>
                                            
                                            
                                        </Columns>
                                    </asp:DataGrid>
                                    </div>
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
			</form>
			
		</td>
		
		<td width="6" class="rightShadow" valign="top">
			<img src="images/white.gif" width="6" height="6" /></td>
	</tr>
	
	<!-- bottom shadow -->
	<tr>
		<td height="6" class="bottomShadow">
			<img src="images/white.gif" width="6" height="6" /></td>
		
		<td width="6" height="6">
			<img src="images/shadow_corner.gif" width="6" height="6" /></td>
	</tr>
</table>




</body>
</html>
